﻿using BUS;
using DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineDigitalCameraWebsite.Users
{
    public partial class OrderList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDS();
            }
        }

        private void LoadDS()
        {
            OrdersBUS cBUS = new OrdersBUS();
            List<Order> list = new List<Order>();
            int userid = int.Parse(Session["UserID"].ToString());
            list = cBUS.GetListAll_Sort_User(userid);
            gvDS.DataSource = list;
            gvDS.DataBind();

        }
        protected void btnOK_Click(object sender, EventArgs e)
        {

        } 
        protected void gvDS_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvDS.PageIndex = e.NewPageIndex;
            LoadDS();
        }

        protected void gvDS_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gvDS.EditIndex = e.NewEditIndex;
            LoadDS();
        }

        protected void gvDS_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvDS.EditIndex = -1;
            LoadDS();
        }

        protected void gvDS_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
        }
        public void ShowMessage(string Content)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript'>alert('" + Content + "');</script>");
        }
        protected void gvDS_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void gvDS_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Label lb1 = (Label)gvDS.Rows[e.RowIndex].FindControl("id1");
            int ma = Convert.ToInt32(lb1.Text);
            OrdersBUS cBUS = new OrdersBUS();
            if (cBUS.Delete(ma))
            {
                lbThongBao.Text = "Xóa Orders thành công! ";
                LoadDS();
            }
            else
            {
                lbThongBao.Text = "Xóa Orders thất bại !";
            }

        }

        protected void gvDS_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbl = (Label)e.Row.FindControl("lblordersStatus");
                if (lbl.Text == "True")
                {
                    lbl.Text = "Đã Duyệt";
                }
                else
                {
                    lbl.Text = "Chưa Duyệt";
                }
               // lbl.DataBind();
            }
        }

        protected void gvDS_DataBound(object sender, EventArgs e)
        {

        }
    }
}